package com.ruoyi.framework.dataPermission;

import cn.xbatis.core.mybatis.mapper.intercept.Invocation;
import cn.xbatis.core.mybatis.mapper.intercept.MethodInterceptor;
import com.ruoyi.common.annotation.DataPermission;

public class XbatisDataPermissionMethodInterceptor implements MethodInterceptor {
    @Override
    public Object around(Invocation invocation) throws Throwable {
        if (invocation.getMethod().isAnnotationPresent(DataPermission.class)) {
            try{
                DataPermissionHolder.setDataPermission(invocation.getMethod().getAnnotation(DataPermission.class));
              return   invocation.proceed();
            }finally {
                DataPermissionHolder.removeDataPermission();
            }
        }
        return   invocation.proceed();
    }
}
